package dk.dtu.student.assignmentfour;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListAdapter extends ArrayAdapter<SmsThread> {

	private List<SmsThread> items;
	
	public ListAdapter(Context context, int resource, List<SmsThread> items) {
	    super(context, resource, items);	
	    this.items = items;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
	
	    View v = convertView;
	
	    if (v == null) {
	        LayoutInflater vi = LayoutInflater.from(getContext());
	        v = vi.inflate(R.layout.listview_listitem, null);
	    }
	
	    SmsThread p = items.get(position);
	
	    if (p != null) {
	
	        TextView name = (TextView) v.findViewById(R.id.contactName);
	        TextView mood = (TextView) v.findViewById(R.id.mood);
	
	        if (null != name) {
	        	name.setText(p.getContactName());
	        }
	        
	        if (null != mood) {
	        	mood.setText("Mood: " + p.getThreadMood());
	        }
	    }
	
	    return v;
	}
}